package com.xquant.system.controller;
import com.xquant.common.core.web.controller.BaseController;
import com.xquant.common.core.web.domain.AjaxResult;
import com.xquant.common.core.web.page.TableDataInfo;
import com.xquant.common.log.annotation.Log;
import com.xquant.common.log.enums.BusinessType;
import com.xquant.common.security.annotation.InnerAuth;
import com.xquant.common.security.annotation.RequiresPermissions;
import com.xquant.common.security.utils.ExcelUtil;
import com.xquant.system.api.domain.TsysInterfaceLog;
import com.xquant.system.service.ITsysInterfaceLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/interfaceLog")
public class SysInterfaceLogController extends BaseController
{
    @Autowired
    private ITsysInterfaceLogService tsysInterfaceLogService;

    /**
     * 查询导入日志列表
     */
    @RequiresPermissions("system:interfacelog:list")
    @GetMapping("/list")
    public TableDataInfo list(TsysInterfaceLog tsysInterfaceLog)
    {
        startPage();
        List<TsysInterfaceLog> list = tsysInterfaceLogService.selectTsysInterfaceLogList(tsysInterfaceLog);
        return getDataTable(list);
    }

    /**
     * 远程调用条件查询导入日志列表
     */
    @PostMapping("/queryLog")
    public TableDataInfo queryLog(@RequestBody TsysInterfaceLog tsysInterfaceLog)
    {
        startPage();
        List<TsysInterfaceLog> list = tsysInterfaceLogService.selectTsysInterfaceLogList(tsysInterfaceLog);
        return getDataTable(list);
    }

    /**
     * 导出导入日志列表
     */
    @RequiresPermissions("system:interfacelog:export")
    @Log(title = "导出导入日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TsysInterfaceLog tsysInterfaceLog)
    {
        List<TsysInterfaceLog> list = tsysInterfaceLogService.selectTsysInterfaceLogList(tsysInterfaceLog);
        ExcelUtil<TsysInterfaceLog> util = new ExcelUtil<>(TsysInterfaceLog.class);
        util.exportExcel(response, list, "导入日志数据");
    }

    /**
     * 获取导入日志详细信息
     */
    @RequiresPermissions("system:interfacelog:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(tsysInterfaceLogService.selectTsysInterfaceLogById(id));
    }

    /**
     * 获取导入日志详细信息
     */
    @RequiresPermissions("system:interfacelog:query")
    @GetMapping(value = "/icode/{id}")
    public AjaxResult getInfoByICode(@PathVariable("id") String id)
    {
        return AjaxResult.success(tsysInterfaceLogService.queryTsysInterfaceLogByICode(id));
    }


    /**
     * 新增导入日志
     */
    @PostMapping
    public AjaxResult add(@RequestBody TsysInterfaceLog tsysInterfaceLog)
    {
        return toAjax(tsysInterfaceLogService.insertTsysInterfaceLog(tsysInterfaceLog));
    }

    /**
     * 修改导入日志
     */
    @RequiresPermissions("system:interfacelog:edit")
    @Log(title = "修改导入日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TsysInterfaceLog tsysInterfaceLog)
    {
        return toAjax(tsysInterfaceLogService.updateTsysInterfaceLog(tsysInterfaceLog));
    }

    /**
     * 删除导入日志
     */
    @RequiresPermissions("system:interfacelog:remove")
    @Log(title = "删除导入日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tsysInterfaceLogService.deleteTsysInterfaceLogByIds(ids));
    }

    /**
     * 删除导入日志
     */
    @RequiresPermissions("system:interfacelog:remove")
    @Log(title = "清空导入日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/clean")
    public AjaxResult clearAll()
    {
        return toAjax(tsysInterfaceLogService.clearAll());
    }
}